package ru.study.thinkin.chapter13;

import java.util.HashMap;
import java.util.Map;

public class PetCount3 extends PetCount {
	
	private Map<Class<? extends Pet>, Integer> map = new HashMap<Class<? extends Pet>, Integer>();

	public static void countPets(PetCreator creator) {
		PetCount3 p3 = new PetCount3();

		for (Pet pet : creator.arrayList(15)) {
			
			for (Class petclass : creator.getTypes()) {
			
				if (petclass.isInstance(pet)) {
					Integer val = p3.map.get(petclass);

					if (val == null) {
						p3.map.put(petclass, 1);
					} else {
						p3.map.put(petclass, val + 1);
					}
				}

			}
		}
		System.out.println(p3.map);
	}

	public static void main(String[] args) {
		countPets(new ForNameCreator());

	}

}
